# 待办清单数据模型
from models import db
from datetime import datetime

class Todo(db.Model):
    """待办事项模型"""
    __tablename__ = 'todos'
    
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False)  # 任务标题
    description = db.Column(db.Text)  # 任务描述
    priority = db.Column(db.String(20), default='medium')  # 优先级: high, medium, low
    category = db.Column(db.String(50), default='其他')  # 分类: 工作, 生活, 学习等
    deadline = db.Column(db.DateTime)  # 截止日期
    completed = db.Column(db.Boolean, default=False)  # 完成状态
    created_at = db.Column(db.DateTime, default=datetime.utcnow)  # 创建时间
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)  # 更新时间
    
    def to_dict(self):
        """转换为字典"""
        return {
            'id': self.id,
            'title': self.title,
            'description': self.description,
            'priority': self.priority,
            'category': self.category,
            'deadline': self.deadline.isoformat() if self.deadline else None,
            'completed': self.completed,
            'created_at': self.created_at.isoformat(),
            'updated_at': self.updated_at.isoformat()
        }
    
    def __repr__(self):
        return f'<Todo {self.title}>'

